package com.zhida.smartcontrol.pagectrl.projectdetail.warning;

import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.yanzhenjie.kalle.Params;
import com.zhida.smartcontrol.common.Api;
import com.zhida.smartcontrol.common.bean.LampBean;
import com.zhida.smartcontrol.knet.KalleCallBack;
import com.zhida.smartcontrol.mvp.BasePresenterImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * author: tanjianpei
 * date: 2019/10/11 011 9:14
 * description:
 */

public class WarningPresenter extends BasePresenterImpl<WarningContract.View> implements WarningContract.Presenter {

    @Override
    public void requestWarning(String switchType, String projectBaseId, int page, boolean showLoading) {
        if (TextUtils.isEmpty(projectBaseId)) {
            return;
        }
        Params params = Params.newBuilder()
                .add("pageNo", page)
                .add("projectBaseId", projectBaseId)
                .add("pageSize", 10)
                .add("type", switchType)
                .build();
        mKalleCenter.get(Api.WARNING_LIST, params, showLoading, new KalleCallBack() {
            @Override
            public void onSuccess(String result, String msg) {
                WarningBean warningBean = JSON.parseObject(result, WarningBean.class);
                mView.showData(warningBean);
            }

            @Override
            public void onFailed(String msg) {
                mView.showMsg(msg);
            }
        });
    }

    @Override
    public void processWarn(String alarmType, String id, String status, boolean showLoading) {
        Map<String, Object> params = new HashMap<>();
        params.put("alarmType", alarmType);
        params.put("id", id);
        params.put("status", status);
        mKalleCenter.postJson(Api.PROCESSWARN, params, showLoading, new KalleCallBack() {
            @Override
            public void onSuccess(String result, String msg) {
                mView.showMsg(msg);
                mView.processWarn();
            }

            @Override
            public void onFailed(String msg) {
                mView.showMsg(msg);
            }
        });
    }
}
